﻿using UnityEngine;
using System.Collections;



public class Food : Entity
{

    protected bool isEnable_ = true;
    public float scale = 1.0f;
    public   bool isEnable()
    {
        return this.isEnable_;
    }
    public virtual void SetDisable()
    {
        this.isEnable_ = false;
        this.visible = false;
    }

    public override void UpdateMS()
    {
        this.CheckLiftCycle();
    }

    public override bool Init()
    {
        base.Init();



        return true; 
    }
    void CheckLiftCycle()
    {
        if (isEnable_ == false)
        {
            current++;
            if (current > lifecycle)
            {
                this.isEnable_ = true;
                this.visible = true;
                this.current = 0;
            }
        }
    }
    int current = 0;
    int lifecycle = 300;
    public bool isAlive = true;//是否活着
}






//孢子
public class FoodChild : Food
{
    //吐出一段距离后才可吃掉
    /*
     创建出来后直接跑到目标点
     */

 
    public override void SetDisable()
    {
        // destroy;

        //  this.Dispose();
        this.isAlive = false;
    }
    public override void OnExit()
    {
        FoodsMgr.ins.RemoveFoodChild(this);

        base.OnExit();
    }
    public override void UpdateMS()
    {

        // move 
        _MovingStep++;
        if (_MovingStep > 40)
        {//移动1S
            this.isEnable_ = true;

        }
        else
        {

            float speed = 5.0f;

            int d = this.dir;
            if (d <= 0) d = 0;
            float dd = d * DATA.ONE_DEGREE;//一度的弧度

            // float  y_delta = Mathf.Sin(dd);
            //  float  x_delta = Mathf.Cos(dd);



            if (x < 0) x = 0;
            if (x > Config.MAX_MAP_WIDTH) x = Config.MAX_MAP_WIDTH;

            if (y < 0) y = 0;
            if (y > Config.MAX_MAP_HEIGHT) y = Config.MAX_MAP_HEIGHT;

            this.y = this.y + speed * y_delta;
            this.x = this.x + speed * x_delta;


        }
        if (this.isAlive == false)
        {
            //   this.Dispose();
            this.LazyDispose();
        }

    }
    public override bool Init()
    {
        base.Init();


        this.value = 10;
        this.scale = Mathf.Sqrt((float)this.value / Mathf.PI) + 3.0f;

        this.isEnable_ = false;
       
        return true;
    }
    public int _MovingStep = 0;//移动多少次
    public float x_delta;
    public float y_delta;
 

}
